package tmall.portal.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import tmall.framework.exception.TException;
import tmall.portal.dict.PortalExceptionDict;
import tmall.portal.eobj.UserEobj;
import tmall.portal.mapper.UserMapper;
import tmall.portal.service.UserService;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public UserEobj queryUserByName(String name) {
        if(StringUtils.isEmpty(name)){
            throw new TException(PortalExceptionDict.USERNAME_OR_PASSWORD_ABSENT);
        }
        return  userMapper.queryUserByName(name);
     }

    @Override
    public boolean registerUser(UserEobj userEobj) {
        return false;
    }

    @Override
    public boolean deleteUser(long id) {
        return false;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if(StringUtils.isEmpty(username)){
            return null;
        }
        return  userMapper.queryUserByName(username);
    }
}
